<?php
if($_GET['key'] != sha1($_GET['domain']."ssiuhIUAHSiu!husashu11dd@kjdjsah==")) {
echo 1001;
} else {


if(substr($_GET["domain"],0,4) == 'www.') {
		$domain=substr($_GET["domain"],4);
	}else{
		$domain=$_GET["domain"];
}

include_once('config.php');
function getDatFile() {
global $domain;
	$link = mysql_connect(Config::$db_host, Config::$db_user, Config::$db_pass) or die("Link database error!");
	mysql_select_db(Config::$db_name);
	$sql = "select count(*) as num from licence where domain='".$domain."'";
	$query = mysql_query($sql,$link);
	$arr = mysql_fetch_array($query, MYSQL_ASSOC);
	if($arr['num'] <= 0){
		return 1002;
	}
	$sql = "SELECT * FROM licence WHERE domain='".$domain."' AND licence_type in('1','2') ORDER BY id ASC";
	$result = mysql_query($sql,$link);
	$row = array();
	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
		$res[] = $row;
	}
	return $res;
}
$key = 'ssiuhIUAHSiu!husashu11dd@kjdjsah==';
$dat_data = getDatFile();
if($dat_data==1002){
echo 1002;
exit;
}
$num = sizeof($dat_data);
$l6 = array();
if($num > 0) {
	for($i = 0; $i < $num; $i++) {
		if($dat_data[$i]['licence_type'] == '1') {
			$l0 = strtolower($dat_data[$i]['domain']);
			$l1 = md5($l0.$key);
			$l2 = $dat_data[$i]['start_time'];
			$l3 = md5($dat_data[$i]['start_time'].$key);
			$l4 = $dat_data[$i]['end_time'];
			$l5 = md5($dat_data[$i]['end_time'].$key);
		} else if($dat_data[$i]['licence_type'] == '2') {
			$tmp = array($dat_data[$i]['template_id'],md5(strtolower($dat_data[$i]['domain']).$dat_data[$i]['template_name'].$key),$dat_data[$i]['start_time'],md5($dat_data[$i]['start_time'].$key),$dat_data[$i]['end_time'],md5($dat_data[$i]['end_time'].$key));
			$l6[$dat_data[$i]['template_name']] = $tmp;
		}
	}
}
$dat .= '$l0="'.$l0.'" ;';
$dat .= '$l1="'.$l1.'" ;';
$dat .= '$l2="'.$l2.'" ;';
$dat .= '$l3="'.$l3.'" ;';
$dat .= '$l4="'.$l4.'" ;';
$dat .= '$l5="'.$l5.'" ;';
$dat .= '$l6=\''.serialize($l6).'\' ;';
die($dat);
}

?>